package GUI;

import model.*;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;


public class TerritoryPanel extends JPanel implements Observer, MouseListener{
	Observable territorySubject;
	private Territory territory;
	OrderPanel orderPanel;
	MapPanel mapPanel;
	
	public TerritoryPanel(Observable _Subject, OrderPanel _orderPanel, MapPanel _mapPanel){
		  territorySubject = _Subject;
		  orderPanel = _orderPanel;
		  mapPanel = _mapPanel;
		  territory = (Territory)territorySubject;
		   territorySubject.addObserver(this);
		   add(new JLabel(territory.getLocation()));
		   this.setBackground(territory.getOwner().getHue());
	       this.addMouseListener(this); 
	}
	
	public void update(Observable obs, Object arg){
		this.setBackground(territory.getOwner().getHue());
		if (orderPanel.getTerritory() == territory)
			orderPanel.update(territory);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		if (!territory.getValid()) return;
		mapPanel.clearBorder();
		this.setBorder(BorderFactory.createLineBorder (Color.black, 3));
		orderPanel.update(territory);
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		
	}

	

}
